class Solution {
    public static int minPathSum(int[][] grid) {
        int col=grid[0].length;
        int row=grid.length;
        int[][] arr=new int[row][col];
        for(int i=0;i<row;i++) {
            for(int n=0;n<col;n++) {
                if(i==0&&n==0) {
                    arr[i][n]=grid[0][0];
                } else if(i==0&&n!=0) {
                    arr[i][n]=arr[i][n-1]+grid[i][n];
                } else if(i!=0&&n==0) {
                    arr[i][n]=arr[i-1][n]+grid[i][n];
                } else {
                    arr[i][n]=Math.min(arr[i-1][n],arr[i][n-1])+grid[i][n];
                }
            }
        }
        return arr[i-1][n-1];
    }

    public static void main(String[] args) {
    }
}
//class Base {
//    Base() {
//        System.out.println("sd");
//    }
//}
//class Alpha extends Base {
//    public static void main(String[] args) {
//        new Alpha();
//        new Base();
//    }
//}
//public class lc64 {
//    public static void main(String[] args) {
//        boolean b = true?false:true==true?false:true;
//        System.out.println(b);
//    }
//}
